<template>
  <div class="addCorp">
    <div class="table-header">
      <p>添加公司</p>
    </div>
    <form>
      <div class="form-item">
        <label class="form-item-left">手机号码</label>
        <div class="form-item-right">
          <input type="text" v-model="tel">
        </div>
      </div>
      <div class="form-item">
        <label class="form-item-left">公司名称</label>
        <div class="form-item-right">
          <input type="text" v-model="name">
        </div>
      </div>
      <div class="form-item">
        <label class="form-item-left">法人代表</label>
        <div class="form-item-right">
          <input type="text" v-model="legal">
        </div>
      </div>
      <div class="form-item">
        <label class="form-item-left">注册资本</label>
        <div class="form-item-right">
          <input type="text" v-model="fund">
        </div>
      </div>
      <div class="form-item">
        <label class="form-item-left">公司规模</label>
        <div class="form-item-right">
          <Select
            width="195px"
            v-model="scale"
            placeholder="公司规模">
            <!-- 这里也可以用对象数组 [{},{},{}] 循环，key值不重复就行，value是你要得到的值，双大括号中是你要显示的值 -->
            <Option
              v-for="item of [{key: '0', value: '(1-10)'},
              {key: '1', value: '(11-50)'},
              {key: '2', value: '(51-100)'},
              {key: '3', value: '(101-500)'},
              {key: '4', value: '(501-1000)'},
              {key: '5', value: '(1001-5000) '},
              {key: '6', value: '(5001-10000)'},
              {key: '7', value: '(>10000)'}]"
              :key="item.key"
              :value="item.key">
              {{ item.value }}
            </Option>
          </Select>
        </div>
      </div>
      <div class="form-item">
        <label class="form-item-left">融资情况</label>
        <div class="form-item-right">
          <Select
            width="195px"
            v-model="fin"
            placeholder="融资情况">
            <Option
              v-for="item of [{key: '0', value: '天使轮'},
              {key: '1', value: 'A轮'},
              {key: '2', value: 'B轮'},
              {key: '3', value: 'C轮'},
              {key: '4', value: '不需要融资'}]"
              :key="item.key"
              :value="item.key">
              {{ item.value }}
            </Option>
          </Select>
        </div>
      </div>
      <div class="btn primary" @click="addCompany">添加</div>
    </form>
  </div>
</template>
<script>
import api from '@/api/corpInfo';
import Select from '@/components/select/Select';
import Option from '@/components/select/Option';

export default {
  name: 'AddCorp',
  beforeRouteEnter(to, from, next) {
    if (sessionStorage.getItem('loginType') !== '4') {
      next({ path: '/login' });
    }
    next((vm) => {
      vm.$emit('route-switch', window.location.href.split('/').pop());
    });
  },
  data() {
    return {
      tel: '',
      name: '',
      legal: '',
      fund: '',
      scale: '',
      fin: '',
    };
  },
  methods: {
    addCompany() {
      const params = new URLSearchParams();
      params.append('phoneNum', this.tel);
      params.append('name', this.name);
      params.append('legalPerson', this.legal);
      params.append('capital', this.fund);
      params.append('scale', this.scale);
      params.append('fin', this.fin);
      api.applyInvolve(params).then(async (response) => {
        if (response.data.code === 200) {
          this.$alert('添加成功');
          this.$router.push({ name: 'corpInfo' });
        } else {
          this.$alert(response.data.message);
        }
      });
    },
  },
  components: {
    Select,
    Option,
  },
};
</script>
<style lang="less">
@import url(../../../static/style/site.vars.less);
.addCorp {
  // .header {
  //   margin-top: 20px;
  //   font-size: 30px;
  // }
  form {
    .btn {
      width: 22.5%;
    }
  }
}
</style>
